#ifndef __SPRITE_H__
#include "sprite.h"
#endif

/* Defines */
#define TRUE 1
#define FALSE 0
#define RW_GREEN 232
#define RW_RED 202
#define RW_YELLOW 253
#define CY_GREEN 215

//Deaths
#define MAX_DEATHS 10

//Canyon
#define CN_DEATH_BY_SHOT      0
#define CN_DEATH_BY_COLLISION 1

//Great Wall
#define GW_DEATH_BY_PLANE 0
#define GW_DEATH_BY_CANON 1

//Data cleansing
#define DC_DEATH_BY_DOGY      0
#define DC_DEATH_BY_MISSLE    1
#define DC_DEATH_BY_DELETER   2
#define DC_DEATH_BY_SRDAEMON  3
#define DC_DEATH_BY_ICONHALLS 4

//Perimeter defence
#define PD_DEATH_BY_CRUSH 		2
#define PD_DEATH_BY_GENERALSHOT 0
#define PD_DEATH_BY_WALLSHOOTER 1
#define PD_DEATH_BY_BIGSCREWS   3


//In the wall
#define IW_DEATH_BY_TRAILDOGY	0 
#define IW_DEATH_BY_SADFORCEP	1
#define IW_DEATH_BY_BIGKUDJO  2
#define IW_DEATH_BY_TORNADO   3

//Final confrontation
#define FC_DEATH_BY_CLAP   0
#define FC_DEATH_BY_TSHOT  1

#define CYBLIVES_X      211
#define CYBLIVES_Y	   188 //183
#define CYBLIVES_WIDTH	94
#define CYBLIVES_HEIGHT	11

#define CYBLIVES_INIT	7   //Padding for the cyber lives thingy
#define CYBLIVES_POST	7
#define CYBLIVES_INC	20

#define CYBHELTH_WIDTH	88
#define CYBHELTH_HEIGHT	5
#define CYBHELTH_X  18
#define CYBHELTH_Y	190
#define CYBTOOL_X	205
#define CYBTOOL_Y	167
#define CYBWEAP_X	20
#define CYBWEAP_Y	167

#define RWDLIVES_X     213
#define RWDLIVES_Y	   174 //173
#define RWDLIVES_WIDTH	86
#define RWDLIVES_HEIGHT	13
#define RWDLIVES_INIT	4   //Padding for the real lives thingy
#define RWDLIVES_POST   0	
#define RWDLIVES_INC	20

#define RWDHELTH_WIDTH	84
#define RWDHELTH_HEIGHT	12
#define RWDHELTH_X	22
#define RWDHELTH_Y	174
#define RWDWEAP_X	126 //130
#define RWDWEAP_Y	170 //158

#define CYB_BR_ARROWR_X		282
#define CYB_BR_ARROWR_Y		155
#define CYB_BR_ARROWL_X		22
#define CYB_BR_ARROWL_Y		155

#define REL_BR_ARROWR_X		218
#define REL_BR_ARROWR_Y		160
#define REL_BR_ARROWL_X		80
#define REL_BR_ARROWL_Y		160

#define FRICTION 1
#define SHIP_MAX_LEFT 10
#define SHIP_MAX_RIGHT 300
#define SHIP_MAX_TOP 20
#define SHIP_MAX_BOTTOM 160-20
#define FIRST_MAX_LEFT 10
#define FIRST_MAX_RIGHT 310
#define FIRST_MAX_TOP 10
#define FIRST_MAX_BOTTOM 150
#define MENU_MAX_BOTTOM 200-15
#define SHELL_MAX_LEFT 195
#define SHELL_MAX_RIGHT 310
#define SHELL_MAX_TOP 10
#define SHELL_MAX_BOTTOM 200-25

#define MOUSECENTERX 320
#define MOUSECENTERY 160

//#define PAN_MUL_X 32
#define PAN_MUL_X 31
/* PAN_DIV_X should be the horizontal range of the ship */
#define PAN_DIV_X	290
#define PAN_MUL_Y 32
/* PAN_DIV_Y should be the vertical range of the ship */
#define PAN_DIV_Y 120


#define DXPERMICKEY 15
#define DYPERMICKEY 9
#define MAXDX 9
#define MAXDY 6
#define TARGETBASE 0
#define PSHIPBASE  0
#define CSHIPBASE  0
#define DAMGSTAR   50
#define BR_ARROWR  51
#define BR_ARROWL  52

#define RMID_EXPLOBASE  53
#define RBIG_EXPLOBASE  71
#define RSML_EXPLOBASE  62
#define CMID_EXPLOBASE  53
#define CBIG_EXPLOBASE  63
#define CSML_EXPLOBASE  58

#define TSHIPBASE       68   //City of light ship
#define SHOTCOLORBASE 253

#define NUMCYBEXPLFRAMES 5
#define NUMRWDEXPLFRAMES 9

enum { INPUT_KEYBOARD,INPUT_MOUSE,INPUT_JOY };

enum { VIEW_FIRSTPERSON=1,
	   VIEW_TOPDOWN,
	   VIEW_RWDSHIP,
	   VIEW_CYBSHIP,
	   VIEW_SHELL
	   };

enum { SHOT_NONE,SHOT_WEAPON,SHOT_TOOL };
enum 
{ 
	EFFECT_NONE,
	EFFECT_LEFT_HIT,
	EFFECT_RIGHT_HIT,
	EFFECT_FLASH,
	EFFECT_EXPLOSION 
};

#define SPRSIZE struct s_sprsize
SPRSIZE
{
 long biggest;
 long smallest;
 long average;
};

typedef struct
{
	short centerx, centery;
	short multx, multy;
	short x, y;
	unsigned char but1, but2;
	short tempx, tempy, buttons;
} JOYDATA;

typedef struct 
{
	short	x,y;			/* Ship's x,y coordinates */
	short offx,offy;	/* Offset for center of sprite */
	short dx,dy;    	/* change in x,y each frame */
	short tcx,tcy;    /* Targeting cursor x,y */
	short pitch;    	/* Pitch angle of ship's nose from -3 to +3 */
	short bank;       /* Bank angle of ship from -3 to +3 */
	short cpitch; 	  	/* current pitch */
	short cbank;		/* current bank */
	long	cursprite;	/* Current sprite # */
	short leftwingx,leftwingy;
	short rightwingx,rightwingy;
	long	hitpoints;
	long	lives;
} playerstruct;

typedef struct 
{
	short	x,y;			/* Ship's x,y coordinates */
	short offx,offy;	/* Offset for center of sprite */
	short dx,dy;    	/* change in x,y each frame */
	short tcx,tcy;    /* Targeting cursor x,y */
	short pitch;    	/* Pitch angle of ship's nose from -3 to +3 */
	short bank;       /* Bank angle of ship from -3 to +3 */
	short cpitch; 	  	/* current pitch */
	short cbank;		/* current bank */
	long	cursprite;	/* Current sprite # */
	short leftwingx,leftwingy;
	short rightwingx,rightwingy;
} joystruct;

#define NUMBLINKFRAMES  16
#define BLINK struct s_blinking
BLINK 
 {
 long  numframes;  //Number of frames to display the text
 unsigned char tswitch;    //toggle switch
 char  blinktext[50];
 };


enum {
   SPC_COASTD=0,
   SPC_DATACL1,
   SPC_DATACL2,
   SPC_DATACL3,
   SPC_DATACL4,
   SPC_FINALC1,
   SPC_PDEFEN1,
   SPC_PDEFEN2,
   SPC_FIREWAL,
   SPC_INWALL,
   SPC_CITYLT,
   SPC_GRWALL,
   SPC_FINALC2,
   SPC_FINALC3,
   MAX_SPECCONDS
};

#define MAX_SPESPRITES 10
#define SPCOND struct s_spcond
SPCOND  
{
  long  numspecsprites;
  long  solved;
  long  specsprites[MAX_SPESPRITES];
};

#define MAX_BRANCHES 15 
#define BRANCH struct s_branch
BRANCH
{
long ulx,uly,lrx,lry;
long branchframe;
};

#define UTILITY struct s_utility
UTILITY  
{
  char  utilname[16];
  char  utilnum:7;
  char  utilaquired:1;
};

/*Scenes*/
enum {
 SC_COASTD=0,
 SC_CANYON,
 SC_GRWALL,
 SC_PORTAL,
 SC_INFNET,
 SC_CITYLT,
 SC_DATACL,
 SC_PDEFEN,
 SC_FIREWL,
 SC_INWALL,
 SC_FINALC
};

enum  //Real World Weapons
 {
  WP_Thunderbolt,
  WP_Viper,
  MAX_RWDWEAPONS
};

enum
{
  WP_Cyclone=3,
  WP_HexRipper1,
  WP_HexRipper2,
  WP_StunHammer,
  WP_CodeSlammer,
  WP_AiresMod,
  WP_AiresCom,
  WP_AIRES,
  MAX_CYBWEAPONS
};

enum  //Tools
 {
  TL_DamageRepair=0,
  TL_AccessTool,
  TL_Matrix=1,
  TL_Passcode1,
  TL_Passcode2,
  TL_LabKey,
  TL_TraceCutter1,
  TL_TraceCutter2,
  MAX_CYBTOOLS,
  TL_Icon,  /*These are things that are hit with tools, even if they are not*/
  TL_Dogy,  /*tools per se. They are marked this way for consistency*/
  TL_Dtag,
  TL_Circ,
  TL_Switch,
  TL_Tornado
 };

#define weapname    utilname
#define weaptype    utiltype
#define weapnum     utilnum
#define weapaquired utilaquired

#define toolname    utilname
#define tooltype    utiltype
#define toolnum     utilnum
#define toolaquired utilaquired
#define  INITIAL_LIFE 	500
#define  INITIAL_LIVES  4

#ifdef _PLAYER_
long *g_coordbuf = 0;
playerstruct  g_player;
joystruct g_joyplayer;
long	g_viewmode=VIEW_SHELL;
long	g_windowx=0;		/* X-offset into the movie window */
long	g_windowy=0;		/* Y-offset into the movie window */
long	g_savewindowx=0;		/* X-offset into the movie window saved for sprite placement */
long	g_savewindowy=0;		/* Y-offset into the movie window saved for sprite placement*/
signed char *g_turntable=0;
long  g_turndataready=0;

#define MAX_SCENES 11
SPRSIZE g_sprsizes[MAX_SCENES]=
{
 25208,	12,	837,
 36180,	12,	1176,
 11180,	12,	231,
 38592,	12,	2003,
 9648,	12,	980,
 2600,	12,	709,
 18480,	16,	978,
 15792,	12,	602,
 19096,	12,	1249,
 7840,	12,	1203,
 54600,	12,	939
};

long g_topcoordbuf[]=
{
	7,4,15,14,23,4,
	8,4,16,13,25,4,
	8,4,17,14,26,4,
	8,4,18,14,26,2,
	8,4,17,14,26,3,
	8,4,17,13,25,3,
	7,4,16,13,23,4
};

u8 g_shotcolor[]={ 
						0xff,0xff,0x00, // Yellow
						0x00,0xff,0xff,   // Cyan
						0xff,0xff,0xff, // White
					 };
char g_shotmult = 3;  // before player gets damage repair unit (tool) the damage
					  // inflicted by damage is multiplied by 3.
char g_powrmult = 1;  // Amount to increase the power of the big guns by
					  // if power grid not wacked. Calculated in CheckSpConds

//globals that tell us if the player has acquired a tool/weapon.

BLINK    g_blinktxt = {0,0};
long     g_deaths[MAX_DEATHS];
long     g_numdeaths=-1;
SPCOND   g_spconds[MAX_SPECCONDS] =
        {
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1,-1,-1}
		};

long     g_numbranches=-1;
BRANCH   g_branchs[MAX_BRANCHES] =
        {
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1},
		 {-1,-1,-1,-1,-1}
		};

UTILITY g_tools[MAX_CYBTOOLS] =
        {
		 "DAMAGE REPAIR",	0,	FALSE,
		 "ACCESS TOOL",	    0,	FALSE,
		 "PASSCODE 1.0",	0,	FALSE,
		 "PASSCODE 2.0",	1,	FALSE,
		 "LAB KEY",			2,	FALSE,
		 "TRACECUTTER 1.0",	3,	FALSE,
		 "TRACECUTTER 2.0",	4,	FALSE
		};


UTILITY g_weaps[(MAX_CYBWEAPONS + MAX_RWDWEAPONS)] =
        {
		 "THUNDERBOLT",		0,	FALSE,
		 "     VIPER",			1,	FALSE,
         "",0,0,
		 "CYCLONE",				2,	FALSE,
		 "HEXRIPPER 1.0",		0,	FALSE,
		 "HEXRIPPER 2.0",		1,	FALSE,
		 "STUNHAMMER",			3,	FALSE,
		 "CODESLAMMER",		4,	FALSE,
		 "AIRES MODULE",		5,	FALSE,
		 "AIRES COMPILER",	5,	FALSE,
		 "AIRES",				5,	FALSE
		};

char g_weapcolors[MAX_CYBWEAPONS + MAX_RWDWEAPONS] =
 {
  202, //ThunderBolt  RED
  254, //Viper        BLUE
  255,
  204, //Cyclone,       RED
  253, //HexRipper 1.0  YELLOW
  224, //HexRipper 2.0  DIRTY YELLOW
  236, //StunHammer     BLUE
  210, //CodeSlammer    ORANGE
  255, //Aires Module   NA
  255, //Aires Compiler NA
  255  //AIRES          WHITE
 };

char g_toolcolors[MAX_CYBTOOLS]=
 {
  255, //Damage Repair  NA
  210, //Access Tool    ORANGE
  210, //Pass Key1      ORANGE
  253, //Pass Key2      YELLOW
  236, //Lab Key        BLUE
  204, //TraceCutter1   RED
  255 //TraceCutter2    WHITE
 };

//char rel_targetedcol[8]   = {232,232,232,232,232,232,232,232}; //Green
char rel_targetflash[8]   = {202,202,202,202,202,202,202,202}; //red
char rel_damagecol[8]   =   {236,236,236,236,236,236,236,236}; //grey
char rel_targetedcol[8]   = {253,253,253,253,253,253,253,253}; //yellow
char rel_targetingcol[8]  = {253,253,253,253,253,253,253,253}; //Yellow

//char cyb_targetedcol[8]   = {215,215,215,215,215,215,215,215}; //Green
char cyb_targetflash[8]   = {204,204,204,204,204,204,204,204}; //red
char cyb_damagecol[8]   = {196,196,196,196,196,196,196,196}; //grey
char cyb_targetedcol[8]   = {253,253,253,253,253,253,253,253}; //Yellow
char cyb_targetingcol[8]  = {253,253,253,253,253,253,253,253}; //Yellow
char cyb_targettoolcol[8] = {236,236,236,236,236,236,236,236}; //Blue

short g_numtools = 0;  // this will only include those picked up
short g_numweaps = 0;  // this will only include those picked up

//tools
u8 g_drep=0;	//damage repair
u8 g_tct1=0;	//trace cutter 1
u8 g_tct2=0;	//trace cutter 2
u8 g_pky1=0;	//pass key 1
u8 g_pky2=0;	//pass key 2
u8 g_spky=0;	//lab key
	//weapons
u8 g_hex2=0;	//hexripper 2
u8 g_amod=0;	//aries module
u8 g_acmp=0;	//aries compiler
u8 g_ares=0;	//aries weapon NOTE! a combination of the aries mod & compiler.
u8 g_stun=0;	//stun hammer
u8 g_cslm=0;	//code slammer
u8 g_cycl=0;	//cyclone
short g_ponged=FALSE;
long g_pongframe=-1;


#else

extern UTILITY  g_weaps[];
extern UTILITY  g_tools[];
extern SPCOND   g_spconds[];
extern BRANCH   g_branchs[];
extern BLINK    g_blinktxt;
extern long     g_deaths[];
extern long g_numbranches;
extern long g_numdeaths;

extern u8 g_drep;	//damage repair
extern u8 g_tct1;	//trace cutter 1
extern u8 g_tct2;	//trace cutter 2
extern u8 g_pky1;	//pass key 1
extern u8 g_pky2;	//pass key 2
extern u8 g_spky;	//lab key
extern u8 g_hex2;	//hexripper 2
extern u8 g_amod;	//aries module
extern u8 g_acmp;	//aries compiler
extern u8 g_ares;	//aries weapon NOTE! a combination of the aries mod & compiler.
extern u8 g_stun;	//stun hammer
extern u8 g_cslm;	//code slammer
extern u8 g_cycl;	//cyclone
extern short g_numtools;  // this will only include those picked up
extern short g_numweaps;  // this will only include those picked up

extern char g_shotmult;
extern char g_powrmult;
extern u8 g_shotcolor[3];
extern int xJoyMax;
extern int yJoyMax;
extern int xJoyMin;
extern int yJoyMin;
extern long *g_coordbuf;
extern long g_shotready;
extern playerstruct g_player;
extern long	g_viewmode;
extern long	g_savewindowx,g_savewindowy;
extern long g_windowx,g_windowy;
extern signed char *g_turntable;
extern long g_turndataready;
extern doplayerdamage(long damage,long effect);
extern long random(long n);
extern int initplayerinfo();
extern drawplayersprite(u8 *buffer);
extern processuserinput(u8 *smackbuf);
extern void playershot(u8 *smackbuf);
extern sprite *g_ramsprites;
void checkShot(short px,short py);
extern int processkeyboard(void);
extern long g_deathSceneGoto; 
extern long g_deathFrameGoto;

extern char g_weapcolors[];
extern char g_toolcolors[];

extern rel_targetedcol[];
extern rel_targetingcol[];
extern rel_targetflash[];

extern cyb_targetflash[];
extern cyb_targetedcol[];
extern cyb_targetingcol[];
extern cyb_targettoolcol[];
extern short g_ponged;
extern long g_pongframe;
extern SPRSIZE g_sprsizes[];
extern rel_damagecol[];
extern cyb_damagecol[];

#endif
